import BasePageCtrl, { AnimType } from "./BasePageCtrl";
import UiManager from "./UiManage";
import n  from "./PlayerDataSys"
 import l from "./frameworkManager"
 import s from "./ScrollViewCtrl"
 import c from "./EngineUtil"
 import u from "./BasePageCtrl"
 import p from "./UiManage"
 import d from "./CashWithDrawRecordPage"

const { ccclass, property } = cc._decorator;

@ccclass
export default class CashWithDrawRecordPageCtrl extends BasePageCtrl {
    @property(cc.Prefab)
    ui = null;

    @property(cc.Node)
    total_cash = null;

    @property(cc.Node)
    extract_record = null;

    onLoad() {
        this.onUILoad();
        this._animType = AnimType.SCALE;
        this._touchControl = false;
        this._hasPeneLock = true;
        this._hasBlack = true;
        this._hasTouchLock = false;
        this._hasBlackTouch = false;
        this._showWinSize = true;
        super.onLoad();
        this.addEvent();
        this.addButtonListen();
        this.scheduleOnce(() => {
            this.setVisibleArea();
        });
    }

    start() { }

    addEvent() { }

    setVisibleArea() {
        let height = cc.winSize.height - this.ui.topNode.height - this.ui.centerNode.height - 150;
        this.ui.ScrollView.height = height;
        this.ui.view.height = height;
        this.ui.view.y = -0.5 * height;
    }

    onUILoad() {
        this.ui = cc.instantiate(this.ui);
        this.node.addChild(this.ui);
    }

    _init(e?) {
        if (e) {
            let { total_cash, extract_record } = e;
            this.total_cash = total_cash;
            this.extract_record = extract_record;
            this.ui.receiptLabel.getComponent(cc.Label).string = c.getCashBalance(this.total_cash) + "元";
            this.ui.userID.getComponent(cc.Label).string = "Player ID:" + n.user_id;
            this.addRecordItem();
        }
    }

    addButtonListen() {
        UiManager.addButtonListen(this.ui.btn_close, this.clickClose, this);
    }

    clickClose() {
        this.hide();
    }

    addRecordItem() {
        this.ui.content.removeAllChildren();
        let e = this.extract_record.records;
        if (!e || (e && e.length === 0)) {
            l.log("提现记录为空");
        } else {
            this.ui.ScrollView.getComponent(s).init(e);
            this.ui.ScrollView.getComponent(s).scrollTotop();
        }
    }

    _onHide() {
        super._onHide();
        this.ui.ScrollView.getComponent(s).recycle();
        this.ui.ScrollView.getComponent(s).scrollTotop();
    }
}
